import os
import shutil
from contextlib import contextmanager
from typing import Generator

@contextmanager
def temp_upload_dir(app) -> Generator[str, None, None]:
    """创建临时上传目录"""
    upload_dir = app.config['UPLOAD_FOLDER']
    os.makedirs(upload_dir, exist_ok=True)
    try:
        yield upload_dir
    finally:
        if os.path.exists(upload_dir):
            shutil.rmtree(upload_dir)

def create_test_file(content: bytes, filename: str) -> str:
    """创建测试文件"""
    filepath = os.path.join('/tmp', filename)
    with open(filepath, 'wb') as f:
        f.write(content)
    return filepath 